/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.repair.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.modules.repair.dto.contract.ContractBuildingDTO;
import org.springblade.modules.repair.entity.BuildingContractPlus;
import org.springblade.modules.repair.entity.BuildingContractPlusHistory;
import org.springblade.modules.repair.entity.MaintainPlanConfig;
import org.springblade.modules.repair.entity.MaintainPlanContent;
import org.springblade.modules.repair.enums.ElevatorMaintainStatusEnums;
import org.springblade.modules.repair.mapper.BuildingContractPlusMapper;
import org.springblade.modules.repair.service.IBuildingContractPlusHistoryService;
import org.springblade.modules.repair.service.IBuildingContractPlusService;
import org.springblade.modules.repair.service.IElevatorContractService;
import org.springblade.modules.repair.service.MaintainPlanConfigService;
import org.springblade.modules.repair.vo.contract.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 项目合同信息 服务实现类
 *
 * @author ysq
 * @since 2022-10-26
 */
@Service
public class BuildingContractPlusServiceImpl extends BaseServiceImpl<BuildingContractPlusMapper, BuildingContractPlus> implements IBuildingContractPlusService {


	@Autowired
	private IBuildingContractPlusHistoryService plusHistoryService;

	@Autowired
	private MaintainPlanConfigService maintainPlanConfigService;

	@Autowired
	private IElevatorContractService elevatorContractService;


	@Override
	public ContractStatusListVo getContractStatusList(Date beginTime, Date endTime) {
		if (beginTime == null) {
			beginTime = DateUtil.offsetDay(new Date(), -30);
			endTime = new Date();
		}
		ContractStatusListVo contractStatusListVo = new ContractStatusListVo();

		BuildingContractPlus buildingContractPlus = new BuildingContractPlus();
		List<BuildingContractPlus> list = baseMapper.list(buildingContractPlus);

		//电梯总数
		contractStatusListVo.setCounts(list.size());

		//处理合同管理状态
		final Map<Integer, List<BuildingContractPlus>> contractExtStatusMap = list.stream().collect(Collectors.groupingBy(BuildingContractPlus::getContractExtStatus));
		//合同扩展状态//1:待续签//2:已续签//3:即将到期//4:已脱保//5:已作废
		Integer[] contractExtStatus = {1, 2, 3, 4, 5};
		List<ContractStatusVo> managementList = new ArrayList<>(16);
		for (Integer status : contractExtStatus) {
			ContractStatusVo contractStatusVo = new ContractStatusVo();
			contractStatusVo.setStatus(status);
			if (status.equals(contractExtStatus[0])) {
				contractStatusVo.setStatusName("待续签");
			} else if (status.equals(contractExtStatus[1])) {
				contractStatusVo.setStatusName("已续签");
			} else if (status.equals(contractExtStatus[2])) {
				contractStatusVo.setStatusName("即将到期");
			} else if (status.equals(contractExtStatus[3])) {
				contractStatusVo.setStatusName("已脱保");
			} else if (status.equals(contractExtStatus[4])) {
				contractStatusVo.setStatusName("已作废");
			}
			List<BuildingContractPlus> buildingContractPluses = contractExtStatusMap.get(status);
			if (buildingContractPluses != null && buildingContractPluses.size() > 0) {
				getContractRatio(contractStatusVo, buildingContractPluses, list.size());

			}
			managementList.add(contractStatusVo);
		}
		contractStatusListVo.setManagementList(managementList);


		Map<Integer, List<BuildingContractPlus>> contractStatusMap = list.stream().collect(Collectors.groupingBy(BuildingContractPlus::getContractStatus));

		//合同状态1:未生效2:已生效3:已到期4:已终止
		Integer[] contractStatus = {1, 2, 3, 4};
		List<ContractStatusVo> enableList = new ArrayList<>(10);
		for (Integer status : contractStatus) {
			List<BuildingContractPlus> buildingContractPluses = contractStatusMap.get(status);
			ContractStatusVo contractStatusVo = new ContractStatusVo();
			contractStatusVo.setStatus(status);
			if (status.equals(contractStatus[0])) {
				contractStatusVo.setStatusName("未生效合同");
			} else if (status.equals(contractStatus[1])) {
				contractStatusVo.setStatusName("已生效合同");
			} else if (status.equals(contractStatus[2])) {
				contractStatusVo.setStatusName("已到期合同");
			} else if (status.equals(contractStatus[3])) {
				contractStatusVo.setStatusName("已终止合同");
			}
			if (buildingContractPluses != null && buildingContractPluses.size() > 0) {
				getContractRatio(contractStatusVo, buildingContractPluses, list.size());
			}
			enableList.add(contractStatusVo);
		}
		contractStatusListVo.setEnableList(enableList);


		Integer[] status = {1, 2, 3};
		List<ContractStatusVo> checkList = new ArrayList<>(3);
		Map<Integer, List<BuildingContractPlus>> statusMap = list.stream().collect(Collectors.groupingBy(BuildingContractPlus::getStatus));
		for (Integer statu : status) {
			ContractStatusVo contractStatusVo = new ContractStatusVo();
			contractStatusVo.setStatus(statu);
			if (statu.equals(status[0])) {
				contractStatusVo.setStatusName("待审核合同");
			} else if (statu.equals(status[1])) {
				contractStatusVo.setStatusName("审核通过合同");
			} else if (statu.equals(status[2])) {
				contractStatusVo.setStatusName("审核不通过合同");
			}
			List<BuildingContractPlus> buildingContractPluses = statusMap.get(statu);
			if (buildingContractPluses != null && buildingContractPluses.size() > 0) {
				getContractRatio(contractStatusVo, buildingContractPluses, list.size());
			}
			checkList.add(contractStatusVo);
		}
		contractStatusListVo.setCheckList(checkList);

		/**
		 * 合同来源
		 * 1:新签
		 * 2:续签
		 * 3:转签
		 * 4:丢失
		 * 5:夺回
		 * 6:新梯移交
		 * 7:免保转签
		 */
		Integer[] contractSource = {1, 2, 3, 4, 5, 6, 7};
		List<ContractStatusVo> sourceList = new ArrayList<>(16);
		Date finalBeginTime = beginTime;
		Date finalEndTime = endTime;
		Map<Integer, List<BuildingContractPlus>> contractSourceMap = list.stream().filter(o -> o.getCreateTime().getTime() > finalBeginTime.getTime() && o.getCreateTime().getTime() < finalEndTime.getTime()).collect(Collectors.groupingBy(BuildingContractPlus::getContractSource));
		for (Integer statu : contractSource) {
			ContractStatusVo contractStatusVo = new ContractStatusVo();
			contractStatusVo.setStatus(statu);
			if (statu.equals(contractSource[0])) {
				contractStatusVo.setStatusName("新签合同");
			} else if (statu.equals(contractSource[1])) {
				contractStatusVo.setStatusName("续签合同");
			} else if (statu.equals(contractSource[2])) {
				contractStatusVo.setStatusName("转签合同");
			} else if (statu.equals(contractSource[3])) {
				contractStatusVo.setStatusName("丢失合同");
			} else if (statu.equals(contractSource[4])) {
				contractStatusVo.setStatusName("夺回合同");
			} else if (statu.equals(contractSource[5])) {
				contractStatusVo.setStatusName("新梯移交合同");
			} else if (statu.equals(contractSource[6])) {
				contractStatusVo.setStatusName("免保转签合同");
			}
			List<BuildingContractPlus> buildingContractPluses = contractSourceMap.get(statu);
			if (buildingContractPluses != null && buildingContractPluses.size() > 0) {
				getContractRatio(contractStatusVo, buildingContractPluses, list.size());
			}
			sourceList.add(contractStatusVo);
			contractStatusListVo.setSourceList(sourceList);
		}


		//用来处理脱保的数据
		List<BuildingContractPlusHistory> plusHistoryList2 = plusHistoryService.list(Wrappers.<BuildingContractPlusHistory>lambdaQuery().between(BuildingContractPlusHistory::getUpdateTime, beginTime, endTime));
		//处理合同走势图
		final List<BuildingContractPlusHistory> plusHistoryList = plusHistoryService.list(Wrappers.<BuildingContractPlusHistory>lambdaQuery().between(BuildingContractPlusHistory::getCreateTime, beginTime, endTime));
		plusHistoryList2.forEach(o -> o.setCreateDate(DateUtil.format(o.getUpdateTime(), "yyyy-MM-dd")));
		plusHistoryList.forEach(o -> o.setCreateDate(DateUtil.format(o.getCreateTime(), "yyyy-MM-dd")));
		final Map<String, List<BuildingContractPlusHistory>> listMap = plusHistoryList.stream().collect(Collectors.groupingBy(BuildingContractPlusHistory::getCreateDate));
		final Map<String, List<BuildingContractPlusHistory>> listMap2 = plusHistoryList2.stream().collect(Collectors.groupingBy(BuildingContractPlusHistory::getCreateDate));
		final long day = DateUtil.betweenDay(beginTime, endTime, true) + 1L;
		List<String> dateList = new ArrayList<>();
		for (int i = 0; i < day; i++) {
			String date = DateUtil.format(DateUtil.offsetDay(endTime, -i), "yyyy-MM-dd");
			dateList.add(date);
		}
		//趋势自定义状态1：新签2:续签3：已脱保，4:新梯移交
		Integer[] customStatus = {1, 2, 3, 4};
		List<ContractTrendVo> contractTrendList = new ArrayList<>(16);
		for (String date : dateList) {
			ContractTrendVo contractTrendVo = new ContractTrendVo();
			contractTrendVo.setDate(date);
			List<BuildingContractPlusHistory> buildingContractPlusHistories = listMap.get(date);
			List<ContractStatusVo> contractStatusList = new ArrayList<>();
			//处理脱保
			ContractStatusVo contractStatusVo1 = new ContractStatusVo();
			ContractStatusVo contractStatusVo2 = new ContractStatusVo();
			ContractStatusVo contractStatusVo3 = new ContractStatusVo();
			ContractStatusVo contractStatusVo4 = new ContractStatusVo();
			contractStatusVo1.setStatus(customStatus[0]);
			contractStatusVo2.setStatus(customStatus[1]);
			contractStatusVo3.setStatus(customStatus[2]);
			contractStatusVo4.setStatus(customStatus[3]);

			final List<BuildingContractPlusHistory> buildingContractPlusHistories1 = listMap2.get(date);
			if (buildingContractPlusHistories1 != null && buildingContractPlusHistories1.size() > 0) {
				final List<BuildingContractPlusHistory> collect3 = buildingContractPlusHistories1.stream().filter(o -> Convert.toInt(o.getContractExtStatus(), -1).equals(contractExtStatus[3])).collect(Collectors.toList());
				contractStatusVo3.setCounts(Convert.toInt(collect3.size(), 0));
				contractTrendVo.setOverdueContractCount(contractStatusVo3.getCounts());
			}

			if (buildingContractPlusHistories != null && buildingContractPlusHistories.size() > 0) {

				//新签
				final List<BuildingContractPlusHistory> collect1 = buildingContractPlusHistories.stream().filter(o -> o.getContractSource().equals(contractSource[0])).collect(Collectors.toList());
				final List<BuildingContractPlusHistory> collect2 = buildingContractPlusHistories.stream().filter(o -> o.getContractSource().equals(contractSource[1])).collect(Collectors.toList());
				final List<BuildingContractPlusHistory> collect4 = buildingContractPlusHistories.stream().filter(o -> o.getContractSource().equals(contractSource[5])).collect(Collectors.toList());

				contractStatusVo1.setCounts(Convert.toInt(collect1.size(), 0));
				contractStatusVo2.setCounts(Convert.toInt(collect2.size(), 0));
				contractStatusVo4.setCounts(Convert.toInt(collect4.size(), 0));

				contractTrendVo.setCreateContractCount(contractStatusVo1.getCounts());
				contractTrendVo.setExtensionContractCount(contractStatusVo2.getCounts());
				contractTrendVo.setNewElevatorContractCount(contractStatusVo4.getCounts());
			}

			contractStatusList.add(contractStatusVo1);
			contractStatusList.add(contractStatusVo2);
			contractStatusList.add(contractStatusVo3);
			contractStatusList.add(contractStatusVo4);
			contractTrendVo.setList(contractStatusList);
			contractTrendList.add(contractTrendVo);
		}
		contractStatusListVo.setContractTrendList(contractTrendList);
		return contractStatusListVo;
	}

	@Override
	public List<BuildingContractPlus> list(BuildingContractPlus buildingContractPlus) {
		return baseMapper.list(buildingContractPlus);
	}

	@Override
	public ContractStatisticVo getContractStatisticInfo() {

		ContractStatisticVo contractStatisticVo = new ContractStatisticVo();
		List<MaintainPlanConfig> list = maintainPlanConfigService.findAll(new MaintainPlanConfig());
		//脱保
		List<MaintainPlanConfig> maintainPlanConfigs = list.stream().filter(o -> o.getMaintainStatus() == ElevatorMaintainStatusEnums.RELEASE_INSURANCE.getId()).collect(Collectors.toList());
		List<MaintainPlanConfig> outList = list.stream().filter(o -> o.getMaintainStatus() == ElevatorMaintainStatusEnums.CONTRACT_OUT_TIME.getId() || o.getMaintainStatus() == ElevatorMaintainStatusEnums.OUT_TIME_STOP.getId() || o.getMaintainStatus() == ElevatorMaintainStatusEnums.OUT_TIME_END.getId() || o.getMaintainStatus() == ElevatorMaintainStatusEnums.OUT_TIME_END_HAS_NEXT.getId()).collect(Collectors.toList());
		List<MaintainPlanConfig> disEnableList = list.stream().filter(o -> o.getMaintainStatus() == ElevatorMaintainStatusEnums.DIS_ENABLE.getId()).collect(Collectors.toList());
		List<MaintainPlanConfig> inTimeList = list.stream().filter(o -> o.getMaintainStatus() == ElevatorMaintainStatusEnums.CONTRACT_IN_TIME.getId()).collect(Collectors.toList());
		contractStatisticVo.setContractElevatorCount(list.size());


		//脱保合同
		contractStatisticVo.setOverdueContractCount(Convert.toInt(maintainPlanConfigs.size(), 0));
		BigDecimal rate1 = Convert.toBigDecimal(contractStatisticVo.getOverdueContractCount()).divide(Convert.toBigDecimal(list.size()), 3, BigDecimal.ROUND_HALF_UP);
		contractStatisticVo.setOverdueContractRatio(rate1.multiply(Convert.toBigDecimal(100)).setScale(1));

		//在保合同
		contractStatisticVo.setEnContractCount(list.size() - contractStatisticVo.getOverdueContractCount());
		BigDecimal rate2 = Convert.toBigDecimal(contractStatisticVo.getEnContractCount()).divide(Convert.toBigDecimal(list.size()), 3, BigDecimal.ROUND_HALF_UP);
		contractStatisticVo.setEnContractRatio(rate2.multiply(Convert.toBigDecimal(100)).setScale(1));

		//待续签
		contractStatisticVo.setDisCreateCount(Convert.toInt(outList.size(), 0));
		BigDecimal rate3 = Convert.toBigDecimal(contractStatisticVo.getDisCreateCount()).divide(Convert.toBigDecimal(contractStatisticVo.getEnContractCount()), 3, BigDecimal.ROUND_HALF_UP);
		contractStatisticVo.setDisCreateRatio(rate3.multiply(Convert.toBigDecimal(100)).setScale(1));

		//拟续签
		contractStatisticVo.setAboutCreateCount(Convert.toInt(disEnableList.size(), 0));
		BigDecimal rate4 = Convert.toBigDecimal(contractStatisticVo.getAboutCreateCount()).divide(Convert.toBigDecimal(contractStatisticVo.getEnContractCount()), 3, BigDecimal.ROUND_HALF_UP);
		contractStatisticVo.setAboutCreateRatio(rate4.multiply(Convert.toBigDecimal(100)).setScale(1));
		//在保(合同期内)
		contractStatisticVo.setInTimeCount(inTimeList.size());
		BigDecimal rate5 = Convert.toBigDecimal(contractStatisticVo.getInTimeCount()).divide(Convert.toBigDecimal(contractStatisticVo.getEnContractCount()), 3, BigDecimal.ROUND_HALF_UP);
		contractStatisticVo.setInTimeRatio(rate5.multiply(Convert.toBigDecimal(100)).setScale(1));
		return contractStatisticVo;
	}

	@Override
	public ContractStatusVo getBuildingCount(Integer type) {
		//0,全部 1:脱保(待续签) 2:在保(合同期内)，4:非在保(拟定保养),8:丢保        11:在保(合同期内)即将到期
		Integer[] types = {0, 1, 2, 3, 4, 5};
		ContractStatusVo contractStatusVo = baseMapper.getBuildingCount(type);
		return contractStatusVo;

	}

	@Override
	public IPage<ContractBuildingVo> getElevatorList(ContractBuildingDTO contractBuildingDTO) {
		Query query = new Query();
		query.setCurrent(contractBuildingDTO.getCurrent());
		query.setSize(contractBuildingDTO.getSize());
		IPage<ContractBuildingVo> page = Condition.getPage(query);
		List<ContractBuildingVo> list = baseMapper.getContractBuildingList(page, contractBuildingDTO);
		if (list.size() > 0) {
			List<Long> buildingIds = list.stream().map(ContractBuildingVo::getBuildingId).collect(Collectors.toList());
			contractBuildingDTO.setBuildingIds(buildingIds);
			List<ContractElevatorVo> contractElevatorList = baseMapper.getContractElevatorList(contractBuildingDTO);
			if (contractElevatorList.size() > 0) {
				Map<Long, List<ContractElevatorVo>> listMap = contractElevatorList.stream().collect(Collectors.groupingBy(ContractElevatorVo::getBuildingId));
				for (ContractBuildingVo contractBuildingVo : list) {
					List<ContractElevatorVo> contractElevatorVos = listMap.get(contractBuildingVo.getBuildingId());
					if (contractElevatorVos == null) {
						continue;
					}
					contractBuildingVo.setList(contractElevatorVos);
					for (ContractElevatorVo contractElevatorVo : contractElevatorVos) {
						Integer maintainStatus = contractElevatorVo.getMaintainStatus();
						if (maintainStatus.equals(ElevatorMaintainStatusEnums.CONTRACT_OUT_TIME.getId()) || maintainStatus.equals(ElevatorMaintainStatusEnums.OUT_TIME_STOP.getId()) || maintainStatus.equals(ElevatorMaintainStatusEnums.OUT_TIME_END.getId()) || maintainStatus.equals(ElevatorMaintainStatusEnums.OUT_TIME_END_HAS_NEXT.getId())) {
							if (maintainStatus.equals(ElevatorMaintainStatusEnums.OUT_TIME_STOP.getId())) {
								contractElevatorVo.setMaintainStatusnName("脱保(合同终止)");
								contractElevatorVo.setDesc(DateUtil.format(contractElevatorVo.getContractEndTime(), "yyyy-MM-dd") + "到期 " + "(已终止" + DateUtil.betweenDay(contractElevatorVo.getContractEndTime(), contractElevatorVo.getNowDate(), true) + "天)");
							} else if (maintainStatus.equals(ElevatorMaintainStatusEnums.OUT_TIME_END.getId())) {
								contractElevatorVo.setMaintainStatusnName("脱保(合同到期)");
								contractElevatorVo.setDesc(DateUtil.format(contractElevatorVo.getContractEndTime(), "yyyy-MM-dd") + "到期 " + "(已到期" + DateUtil.betweenDay(contractElevatorVo.getContractEndTime(), contractElevatorVo.getNowDate(), true) + "天)");
							} else if (maintainStatus.equals(ElevatorMaintainStatusEnums.OUT_TIME_END_HAS_NEXT.getId())) {
								contractElevatorVo.setMaintainStatusnName("脱保(下份合同待生效)");
								BuildingContractPlus buildingContractPlus = baseMapper.getLast(contractElevatorVo.getElevatorId());
								if (buildingContractPlus != null) {
									if (buildingContractPlus.getStopTime() != null) {
										contractElevatorVo.setDesc(DateUtil.format(buildingContractPlus.getStopTime(), "yyyy-MM-dd") + "终止" + "~" + DateUtil.format(contractElevatorVo.getContractBeginTime(), "yyyy-MM-dd") + "续签(存在空档" + DateUtil.betweenDay(buildingContractPlus.getStopTime(), contractElevatorVo.getContractBeginTime(), true) + "天)");
									} else {
										contractElevatorVo.setDesc(DateUtil.format(buildingContractPlus.getContractEndTime(), "yyyy-MM-dd") + "到期" + "~" + DateUtil.format(contractElevatorVo.getContractBeginTime(), "yyyy-MM-dd") + "续签(存在空档" + DateUtil.betweenDay(buildingContractPlus.getContractEndTime(), contractElevatorVo.getContractBeginTime(), true) + "天)");
									}
								} else {
									contractElevatorVo.setDesc(DateUtil.format(contractElevatorVo.getContractBeginTime(), "yyyy-MM-dd") + "开始生效");
								}
							} else {
								contractElevatorVo.setMaintainStatusnName("脱保(待续签)");
								contractElevatorVo.setDesc(DateUtil.format(contractElevatorVo.getContractEndTime(), "yyyy-MM-dd") + "到期 " + "(已到期" + DateUtil.betweenDay(contractElevatorVo.getContractEndTime(), contractElevatorVo.getNowDate(), true) + "天)");
							}
						} else if (maintainStatus.equals(ElevatorMaintainStatusEnums.DIS_ENABLE.getId())) {
							contractElevatorVo.setMaintainStatusnName("非在保(拟定保养)");
							MaintainPlanContent maintainPlanContent = baseMapper.getPlanListByelevatorIds(contractElevatorVo.getElevatorId());
							if (maintainPlanContent != null) {
								contractElevatorVo.setDesc("无合同保养" + DateUtil.betweenDay(maintainPlanContent.getPlanDate(), new Date(), true) + "天");
							}
						} else if (maintainStatus.equals(ElevatorMaintainStatusEnums.CONTRACT_IN_TIME.getId())) {
							//表示即将到期
							Integer contractExtStatus = 3;
							String name = contractElevatorVo.getContractExtStatus().equals(contractExtStatus) ? "即将到期" : "正常服务";
							contractElevatorVo.setMaintainStatusnName("在保(合同期内)-" + name);
							contractElevatorVo.setDesc(DateUtil.format(contractElevatorVo.getContractEndTime(), "yyyy-MM-dd") + "到期 ");
						} else if (maintainStatus.equals(ElevatorMaintainStatusEnums.RELEASE_INSURANCE.getId())) {
							contractElevatorVo.setMaintainStatusnName("丢保");
						}
					}
				}
			}
		}
		page.setRecords(list);
		return page;
	}


	/**
	 * 计算比例
	 *
	 * @param contractStatusVo       各种类型统计对象
	 * @param buildingContractPluses 合同信息
	 * @param counts                 合同总数
	 */
	private void getContractRatio(ContractStatusVo contractStatusVo, List<BuildingContractPlus> buildingContractPluses, Integer counts) {

		List<String> buildingIds = new ArrayList<>(16);
		List<String> elevatorIds = new ArrayList<>(16);
		for (BuildingContractPlus buildingContractPlus : buildingContractPluses) {
			List<String> buildingId = Arrays.asList(buildingContractPlus.getBuildingIds().split(","));
			buildingIds.addAll(buildingId);
			List<String> elevatorId = Arrays.asList(buildingContractPlus.getElevatorIds().split(","));
			elevatorIds.addAll(elevatorId);
		}
		contractStatusVo.setBuildingCounts(buildingIds.stream().distinct().collect(Collectors.toList()).size());
		contractStatusVo.setElevatorCounts(elevatorIds.stream().distinct().collect(Collectors.toList()).size());
		contractStatusVo.setCounts(buildingContractPluses.size());
		BigDecimal divide = Convert.toBigDecimal(contractStatusVo.getCounts()).divide(Convert.toBigDecimal(counts), 2, BigDecimal.ROUND_HALF_UP);
		contractStatusVo.setRatio(divide);
	}


}
